<div id='panel'>
<table width="100%" border="0">
  <tr class='head-tr'>
    <td><strong>Your items being sold</strong></td>
  </tr>
  <tr>
    <td>		
		 <?php
			//Edit Product Price and commission
			if(!empty($_POST['editSellingProductOwnKey'])) {
				$itemId=$_POST['editSellingProductOwnKey'];
				$commission=$_POST['commission'];
				$price=$_POST['price'];
				$sqlSelItemUpd="SELECT * FROM tbl_items where item_id='$itemId'";
				$rstSelItemUpd=mysql_query($sqlSelItemUpd);			
				$rowSelItemUpd=mysql_fetch_array($rstSelItemUpd);	
				$sqlUpdSellingProd="UPDATE tbl_items SET commission='$commission', price ='$price' WHERE item_id=$itemId";
				$rstUpdSellingProd=mysql_query($sqlUpdSellingProd);
				if($rstUpdSellingProd){ 			
					echo "<div id='suc-msg'> Your selling Product edited. </div>"; 
				}
				else {
					echo "<div id='err-msg'> Error on editing product. </div>";
				}
				}
		 ?>
		 <form name="frmProListOwn" id="frmProListOwn" method="post" action="">
		 	<input type="hidden" name="hidDelPro" id="hidDelPro">
            <input type="hidden" name="hidDelProKey" id="hidDelProKey">
             <input type="hidden" name="hidEditSellingItemOwn" id="hidEditSellingItemOwn">
		 <?php		   
				//delete single product		 
			if(!empty($_POST['hidDelPro'])) {
			
				$proId=$_POST['hidDelPro'];
				$sqlDelPro3="Delete from tbl_product where product_id=$proId";
				$rstDelPro3=mysql_query($sqlDelPro3);
				if($rstDelPro3) { 
				
				//setup for auto email
					$sqlEmail="select * from tbl_emails where email_type='Item Deleted'";
					$resEmail=mysql_query($sqlEmail);
					$rowEmail=mysql_fetch_array($resEmail);
					
					$sqlSellers="select * from tbl_items ti, tbl_users tu where tu.user_id=ti.seller_id and ti.product_id='".$proId."'";
					$resSellers=mysql_query($sqlSellers);
					while($rowSellers=mysql_fetch_array($resSellers))
					{
					$subj=str_replace('##_ItemName',$_POST['itemname'],$rowEmail['email_subject']);
					$emailContent=str_replace('##_MerchantName',$rowSellers['username'],$rowEmail['email_body']);
					$emailContent=str_replace('##_ItemName',$_POST['itemname'],$emailContent);
	  $mailmsg="<table width='100%' border='0' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px; line-height:25px'>
  <tr>
    <td width='18%' height='41'><table width='100%' border='0'>
      <tr>
        <td width='19%' height='68'><img src='".$base_url."images/logo.gif'></td>
        <td width='81%'> </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height='32' colspan='2' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;'>".$emailContent."</td>
  </tr>
  
 
</table>
";
		$mail = new PHPMailer(); // defaults to using php "mail()"
	  	$mail->MsgHTML($mailmsg);
		$mail->From       = "mail@swapen.com";
		$mail->FromName   = "Swapen.com";
		$mail->Subject    = $subj;
		$mail->AddAddress($rowSellers['email'], $firstName);
		$mail->Send();
					}
				echo "<div id='suc-msg'> Your product deleted. </div><br>"; 
				}
				}
				  $sqlSelPro="SELECT * FROM tbl_product where posted_by='$userId' and sell_by=0 ORDER BY product_id DESC";
				   $rstSelPro=mysql_query(getPagingQuery($sqlSelPro,$itemPerPage));				  
				   $num=mysql_num_rows($rstSelPro);
				   if($num==0)
					{
					  echo "<div style='border-top:1px solid #CCCCCC;'> </div><br>";
					  echo "<p style='padding:5px;'>No items found on your list...</p><br>";
					  echo "<div style='border-top:1px solid #CCCCCC;'> </div><br>";
					}
				   else {	?>
				   		  <br><table width='100%' border='0' align='center' cellspacing='0'>
						  <tr class='head-tr'>
                          		  <td width="3%">&nbsp;</td>	
				    	    <td width="5%"><strong>S.No</strong></td>								
								  <td width="15%"><strong>Product name </strong></td>
								  <td width="10%"><strong>Condition</strong></td>
								  <td width="9%"  align='center'><strong># of Sellers</strong></td>
								  <td width="7%"><strong>Pick up</strong></td>
								  <td width="6%"><strong>Qty</strong>.</td>
								  <td width="11%"  align='center'> <strong> Comission (PP)</strong></td>
								  <td width="15%"  align='center'> <strong>Price + shipp (PP)</strong></td>
							      <td width="19%">&nbsp;</td>
						    </tr>				 
						 <?php
						 $r=1;
						 while($rowSelPro=mysql_fetch_array($rstSelPro))
					     {						   
						   $productId=$rowSelPro['product_id'];
						   $productName=wordFormater($rowSelPro['product_name'],10);
						   $productTitle = $rowSelPro['product_name'];					   
						   $productPrice=$rowSelPro['product_price'];
						   $productThumb=$rowSelPro['product_thumbnail'];
						   $productImage=$rowSelPro['product_image'];
						   $productSellingType=$rowSelPro['selling_type'];
						   $productShipping=$rowSelPro['shipping'];
						   $productProCondition=$rowSelPro['pro_condition'];
						   $productQuantity=$rowSelPro['quantity'];
						   $commission=$rowSelPro['commission'];
						   $postedBy=$rowSelPro['posted_by'];
						   $postedDate=$rowSelPro['posted_date'];
						   $bargainDate = $rowSelPro['bargain_duration'];
						   if(!empty($productShipping))
						    $productShipping=" + ".$productShipping;
						   else
						     $productShipping=" + Free";
						   $timeLeft = getRemainingTime($bargainDate);
						   if($timeLeft < 0) {
						   		$timeLeft = "<font color='red'>Listing Expired</font>";
						    }
						  $sqlSelNoSeller="SELECT * FROM tbl_items where product_id='$productId'  and seller_id!='$userId'";
				   		  $rstSelNoSeller=mysql_query($sqlSelNoSeller);				
				   		  $numSelNoSeller=mysql_num_rows($rstSelNoSeller);
						  if($numSelNoSeller<=1)
						   $imageExpand="<b><font color='#0000CC'>-</font></b>";
						  else
						   $imageExpand="<a href='javascript:void(0);' onClick='funExpandProduct($productId,\"mchnt\",\"divSellingPro$productId\",$r)'><img src='images/16x16x+.jpg'  border='0'></a>";
						   echo "<tr>
						   <td colspan='10'>
						   <div  id='divSellingPro$productId'>
						   <table width=100% border='0' align='center' cellspacing='0'>
						   <tr>
						    	 <td width='5%' align='center'>$imageExpand</td>	
						   		 <td  width='3%' height='28'> $r </td>					         
								 <td  width='15%'><a href='index.php?SellProduct=$productId' title='$productTitle'> $productName </a></td>
								 <td width='10%'>$productProCondition</td>";
								 
							if($numSelNoSeller!=0)
								echo"<td  width='9%' align='center'><a href='javascript:void(0);' onClick=window.location='index.php?editSellingProduct=$productId'>$numSelNoSeller</a></td>";
							else
								echo"<td  width='9%' align='center'>$numSelNoSeller</td>";
							 
							echo"<td  width='7%'>$productSellingType</td>
								 <td width='6%' align='center'>$productQuantity</td>
								 <td width='11%'  align='right'>$commission</td>
								 <td align='right' width='15%'>$productPrice $productShipping</td>
						      	 <td  width='19%'><a href='index.php?editlist=$productId'>Edit</a> | <a href='javascript:void(0);' onClick=funDelProduct('frmProListOwn','prod',$productId)>Delete</a></td>
						  </tr>
						</table>
						</div>
						</td>
						</tr>";
					    echo "<tr><td colspan='10'> <div style='border-top:1px solid #CCCCCC;'> </div> </td></tr>";   			  
						 	$r++;
						 } ?>
						</table>	
                        <?php
						} 
		   echo"<tr><td colspan='4'><a href='index.php?sell&by=seller'><strong>Add more Items +</strong></a>&nbsp;
		   <a href='seller_store.php?sid=$userId'><strong>Visit Store</strong></a>
		   </td></tr>";
									
	?>
	</form>
	</td>
</tr>
<tr>
	<td><div align="center"><?php
		   $link="mySwapen";
		   echo $disp=getPagingLink($sqlSelPro,$itemPerPage,$link);							   
	 ?></div>
	</td>
</tr><tr>
  <td>
  <a name="editOwn" id="editOwn"></a>
  <?php
  if(!empty($_POST['hidEditSellingItemOwn'])) {
    $sqlSelLstEdit="SELECT * FROM tbl_items where item_id=".$_POST['hidEditSellingItemOwn'];
    $rstSelLstEdit=mysql_query($sqlSelLstEdit);
	$rowSelLstEdit=mysql_fetch_array($rstSelLstEdit);
	$productInfo=getProductById($rowSelLstEdit['product_id']);
  ?>
   <div id="divEditWishlist">
    <form name="frmEditSellingProduct" id="frmEditSellingProduct" method="post" action="">
    <input type="hidden" name="editSellingProductOwnKey" id="editSellingProductOwnKey" />
      <table width="100%" border="0">
        <tr  class='head-tr'>
          <td colspan="3"><strong>Edit product comission and price</strong></td>
        </tr>
        <tr>
          <td height="29">&nbsp;</td>
          <td width="21%"><strong>Product</strong></td>
          <td width="77%"><span class="style1">
            <?php echo $productInfo['product_name']; ?>
          </span></td>
        </tr>
        <tr>
          <td height="31">&nbsp;</td>
          <td><strong>Seller</strong></td>
          <td><?php if(!empty($rowSelLstEdit['seller_id']))
			echo $sellerName=getUser($rowSelLstEdit['seller_id']);
			?></td>
        </tr>
        <tr>
          <td height="31">&nbsp;</td>
          <td><strong>Price (PP)</strong></td>
          <td><input type="text" name="price" id="price" size="33" value="<?php if(!empty($rowSelLstEdit['price']))
			echo $rowSelLstEdit['price'];
			?>"/></td>
        </tr>
        <tr>
          <td height="31">&nbsp;</td>
          <td><strong>Comission (PP)</strong></td>
          <td><input type="text" name="commission" id="commission" size="33" value="<?php if(!empty($rowSelLstEdit['commission']))
			echo $rowSelLstEdit['commission'];
			?>"/></td>
        </tr>
        <tr>
          <td height="34">&nbsp;</td>
          <td>&nbsp;</td>
          <td><label>
            <input type="button" name="editSellingProduct" id="editSellingProduct" value="Edit product" onclick="funEditSellingProductOwn('frmEditSellingProduct',<?php  if(!empty($_POST['hidEditSellingItemOwn'])) echo $_POST['hidEditSellingItemOwn'];?>)" />
          </label></td>
        </tr>
      </table>
      </form>
    </div></td>
    <?php } ?>
</tr>
</table>
</div>